package com.cms.jdbc;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;

import com.cms.model.Customer;

public class DBOper {
	private static String url="jdbc:mysql://localhost:3306/javatest";
	private static String user="root";
	private static String password="a123456";
	private static Connection conn=null;
	private static Statement sta;
	private static ResultSet res=null;
	
	private static  StatementUpdate<Customer> statup=new StatementUpdate<Customer>(Customer.class);
	
	void connect() {
		try {
			conn=DriverManager.getConnection(url, user, password);
			sta=conn.createStatement();
		} catch (SQLException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	}
	
	void close() {
		if(res!=null) {
			try {
				res.close();
			} catch (SQLException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
		}
		if(sta!=null) {
			try {
				sta.close();
			} catch (SQLException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
		}
		if(conn!=null) {
			try {
				conn.close();
			} catch (SQLException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
		}
	}
	
	public int insert(Customer c) {
		connect();
		return statup.executeUpdate(sta, "insert into customer");
	}
	
	
}
